import { Component,PropsWithChildren } from 'react'
import { View,Text,Image,Button } from '@tarojs/components'
import './index.less';
import Taro from '@tarojs/taro';
import { bind,observer } from '@/store/core.store';
import UserStore from '@/store/user.store';
import HttpConfig from '@/constants/http.config';
import { routers } from '@/router';
import { getGitlabRedirectUri, GITLAB_APP_ID } from '@/constants/gitlab';
const baseCls = `legions-login`;
interface IProps{
    store:UserStore
}
@bind({ store: UserStore })
@observer
export default class Index extends Component<PropsWithChildren&IProps> {

    componentWillMount() { }

    componentDidMount() { }

    componentWillUnmount() { }

    componentDidShow() { }

    componentDidHide() { }
    onOauthLogin = () => {
        const ENV_TYPE = Taro.getEnv();
        if (Taro.ENV_TYPE.WEB===ENV_TYPE) {
            let redirect_uri = getGitlabRedirectUri()
            const url = `https://gitlab.hoolinks.com/oauth/authorize?client_id=${GITLAB_APP_ID}&redirect_uri=${redirect_uri}&response_type=code&state=h5&scope=api read_api read_repository write_repository profile read_user`
            location.href = url;
        }
        else {
            Taro.navigateTo({
                url:routers.login_oauth
            })
        }
    }
    render() {
        return (
            <View className={baseCls}>
                <Text className={`text`}>—&nbsp;&nbsp;&nbsp;登录集成平台&nbsp;&nbsp;&nbsp;—</Text>
                <View className={`desc`}>
                    <Image className='img'  src='https://hoolinks-frontend-resources.oss-cn-shenzhen.aliyuncs.com/images/weapp-desc-bg.png'></Image>
                </View>
                <View className='submit'> <Button onClick={this.onOauthLogin}>Gitlab授权登录</Button></View>
            </View>
        )
    }
}
